const express = require('express')
const adminModel = require('../db/model/adminModel')

const route = express.Router();

route.delete('/deleteAdmin', async (req, res) => {
    const {
        adminName
    } = req.query

    try { //这里面有异步操作，且又是发送请求，所有要用try catch包裹下
        const deleteResult = await adminModel.deleteOne({
            adminName //对象简写
        })

        if (deleteResult.deletedCount > 0) { //大于0就是成功删除了 ，deletedCount方法可以看到删除的个数
            return res.send({
                code: 10000,
                msg: "删除管理员" + adminName + "成功",
                data: null
            })
        }

        res.send({
            code: 10001,
            msg: "删除管理员" + adminName + "失败",
            data: null
        })
    } catch (e) {
        console.log("删除管理员失败" + e.message);
        res.send({
            code: 10001,
            msg: "删除管理员异常" + e.message,
            data: null
        })
    }
})
module.exports = route;